package admin

import (
	"game-server/app/common/request"
	"game-server/app/common/response"
	"game-server/app/services"

	"github.com/gin-gonic/gin"
)

// VpnAdd 添加VPN
// @Tags VPN
// @Summary 添加VPN
// @Description 添加VPN
// @Accept json
// @Produce json
// @Param data body request.VpnAddRequest true "添加VPN"
// @Success 200 {object} response.Response
// @Router /gameServer/admin/vpn/add [post]
func VpnAdd(c *gin.Context) {
	var form request.VpnAddRequest
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}

	if err := services.VpnService.CreateVpn(form); err != nil {
		response.BusinessFail(c, err.Error())
		return
	}

	response.Success(c, nil)
}

// VpnEdit 编辑VPN
// @Tags VPN
// @Summary 编辑VPN
// @Description 编辑VPN
// @Accept json
// @Produce json
// @Param data body request.VpnEditRequest true "编辑VPN"
// @Success 200 {object} response.Response
// @Router /gameServer/admin/vpn/edit [post]
func VpnEdit(c *gin.Context) {
	var form request.VpnEditRequest
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}

	if err := services.VpnService.UpdateVpn(form); err != nil {
		response.BusinessFail(c, err.Error())
		return
	}

	response.Success(c, nil)
}

// VpnDelete 删除VPN
// @Tags VPN
// @Summary 删除VPN
// @Description 删除VPN
// @Accept json
// @Produce json
// @Param data body request.VpnDeleteRequest true "删除VPN"
// @Success 200 {object} response.Response
// @Router /gameServer/admin/vpn/delete [post]
func VpnDelete(c *gin.Context) {
	var form request.VpnDeleteRequest
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}

	if err := services.VpnService.DeleteVpn(form); err != nil {
		response.BusinessFail(c, err.Error())
		return
	}

	response.Success(c, nil)
}

// VpnGet 获取VPN详情
// @Tags VPN
// @Summary 获取VPN详情
// @Description 获取VPN详情
// @Accept json
// @Produce json
// @Param data body request.VpnGetRequest true "获取VPN详情"
// @Success 200 {object} response.Response
// @Router /gameServer/admin/vpn/get [post]
func VpnGet(c *gin.Context) {
	var form request.VpnGetRequest
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}

	vpn, err := services.VpnService.GetVpn(form)
	if err != nil {
		response.BusinessFail(c, err.Error())
		return
	}

	response.Success(c, vpn)
}

// VpnList 获取VPN列表
// @Tags VPN
// @Summary 获取VPN列表
// @Description 获取VPN列表
// @Accept json
// @Produce json
// @Param data body request.VpnListRequest true "获取VPN列表"
// @Success 200 {object} response.Response
// @Router /gameServer/admin/vpn/list [post]
func VpnList(c *gin.Context) {
	var form request.VpnListRequest
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}

	res, err := services.VpnService.GetVpnList(form)
	if err != nil {
		response.BusinessFail(c, err.Error())
		return
	}

	response.Success(c, res)
}

// VpnList 获取VPN列表
// @Tags VPN
// @Summary 获取VPN列表门户
// @Description 获取VPN列表门户
// @Accept json
// @Produce json
// @Param data body request.VpnListRequest true "获取VPN列表"
// @Success 200 {object} response.Response
// @Router /gameServer/front/vpn/list [post]
func VpnListFront(c *gin.Context) {
	var form request.VpnListRequest
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}

	res, err := services.VpnService.GetVpnList(form)
	if err != nil {
		response.BusinessFail(c, err.Error())
		return
	}

	response.Success(c, res)
}
